<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false"
		style="height: 30px; overflow: hidden;background-color: #fff">
		<form id="shopGoodsSecondCategorySearchForm">
			<table>
				<tr>
					<th>名称:</th>
					<td><input name="name" placeholder="搜索条件" />
					</td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-magnifying-glass',plain:true"
						onclick="shopGoodsSecondCategorySearchFun();">查询</a> <a
						href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-x-circle',plain:true"
						onclick="shopGoodsSecondCategoryCleanFun();">清空</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div data-options="region:'center',border:false">
		<table id="shopGoodsSecondCategoryDataGrid"
			data-options="fit:true,border:false"></table>
	</div>
</div>
<input type="hidden" id="hiddenCategoryId"
	value="${shopGoodsCategory.categoryId}" />
<script type="text/javascript">
	$(function() {
        shopGoodsSecondCategoryDataGrid = $('#shopGoodsSecondCategoryDataGrid').datagrid({
        url : '${path}/shopGoodsCategory/dataSecondGrid',
        striped : true,
		rownumbers : true,
		pagination : true,
		singleSelect : true,
		fitColumns:false,
	    queryParams: {          
                categoryId: ${shopGoodsCategory.categoryId}            
         },
	    idField : 'categoryId',
		sortName : 'categoryId',
		sortOrder : 'asc',
		pageSize : 20,
		pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,400, 500 ],
		frozenColumns : [ [	
						   {
            width : '140',
            title : '分类编号 ',
            field : 'categoryId',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类名称',
            field : 'categoryName',
            sortable : true
        }, 
								   {
            width : '140',
            title : '父级分类编号',
            field : 'categoryParentId',
            sortable : true
        }, 
								   {
            width : '140',
            title : '排序',
            field : 'categorySort',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类关键字',
            field : 'categoryKeyword',
            sortable : true
        }, 
								   {
            width : '140',
            title : '分类图片',
            field : 'categoryImage',
            sortable : true
        }, 
								   {
            width : '140',
            title : '推荐标志0-不推荐 1-推荐到首页',
            field : 'categoryCommend',
            sortable : true
        }, 
								   {
            width : '140',
            title : '默认标志，0-非默认 1-默认',
            field : 'categoryDefault',
            sortable : true
        }, 
				        {
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsSecondCategory-easyui-linkbutton-search" data-options="plain:true,iconCls:\'icon-search icon-blue\'" onclick="shopGoodsThreeCategorySearchFun(\'{0}\');" >查询</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsSecondCategory-easyui-linkbutton-add" data-options="plain:true,iconCls:\'fi-plus icon-blue\'" onclick="shopGoodsThreeCategoryAddRelateFun(\'{0}\');" >添加</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsSecondCategory-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="shopGoodsSecondCategoryEditFun(\'{0}\');" >编辑</a>', row.categoryId);
                    str += $.formatString('<a href="javascript:void(0)" class="shopGoodsSecondCategory-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="shopGoodsSecondCategoryDeleteFun(\'{0}\');" >删除</a>', row.categoryId);
	                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
            $('.shopGoodsSecondCategory-easyui-linkbutton-search').linkbutton({text:'查询'});
            $('.shopGoodsSecondCategory-easyui-linkbutton-add').linkbutton({text:'新增'});
            $('.shopGoodsSecondCategory-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.shopGoodsSecondCategory-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#shopGoodsSecondCategoryToolbar'
    });
});

/**三级分类绑定二级分类**/
function shopGoodsThreeCategoryAddRelateFun(id){debugger;
   parent.$.modalDialog.handler.dialog('close');
   parent.$.modalDialog({
        title : '三级分类绑定二级分类',
        width : 800,
        height : 600,
        href : '${path}/shopGoodsCategory/addThreeCategoryPage?id='+id,
         buttons : [ {
            text : '确定',
            handler : function() {
                var f = parent.$.modalDialog.handler.find('#shopGoodsThreeCategoryAddForm');
                f.submit();
            }
        } ]
    }); 
}
/**
*三级分类信息查询
**/
function shopGoodsThreeCategorySearchFun(id){
    parent.$.modalDialog.handler.dialog('close');
    parent.$.modalDialog({
        title : '三级分类列表',
        width : 1400,
        height : 600,
        href :  '${path}/shopGoodsCategory/threeCategoryPage?id=' + id
    });
}

/**
*二级分类信息编辑
*/

function shopGoodsSecondCategoryEditFun(id){debugger;
    if (id == undefined) {
        var rows = shopGoodsSecondCategoryDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        shopGoodsSecondCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
     parent.$.modalDialog.handler.dialog('close');
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 600,
        href :  '${path}/shopGoodsCategory/editSecondCategoryPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
               // parent.$.modalDialog.openner_dataGrid = shopGoodsThreeCategoryDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#shopGoodsSecondCategoryEditForm');
                f.submit();
            }
        } ]
    });
}
</script>